package hopital.orm;

import hopital.sql.SqlObject;
import hopital.sql.SqlQuery;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Reservation extends SqlObject{
    
    private int _chambre,_patient;
    private String _dateEntree,_dateSortie,_etat;

    public int getChambre() {
        return _chambre;
    }

    public void setChambre(int _chambre) {
        this._chambre = _chambre;
    }

    public int getPatient() {
        return _patient;
    }

    public void setPatient(int _patient) {
        this._patient = _patient;
    }

    public String getDateEntree() {
        return _dateEntree;
    }

    public void setDateEntree(String _dateEntree) {
        this._dateEntree = _dateEntree;
    }

    public String getDateSortie() {
        return _dateSortie;
    }

    public void setDateSortie(String _dateSortie) {
        this._dateSortie = _dateSortie;
    }

    public Reservation(int _chambre, int _patient, String _dateEntree, String _dateSortie) {
        this._chambre = _chambre;
        this._patient = _patient;
        this._dateEntree = _dateEntree;
        this._dateSortie = _dateSortie;
    }

    public Reservation() {
    }

    
    
    private Reservation(ResultSet _rs) throws SQLException {
       this(_rs.getInt("c_chambre"), _rs.getInt("c_patient"), _rs.getString("c_datee"), _rs.getString("c_dates"));
    }
    
    @Override
    public SqlQuery insert() {
        return new SqlQuery("INSERT INTO t_reservations (c_chambre,c_patient,c_datee) VALUES(?,?,?);",_chambre,_patient,_dateEntree);
    }

    @Override
    public SqlQuery update() {
        return new SqlQuery("UPDATE t_reservations SET c_dates=? WHERE c_id=?;",_id);
    }

    @Override
    public SqlQuery delete() {
        return new SqlQuery("DELETE FROM t_reservations WHERE c_id=?;", _id);
    }

    @Override
    public SqlQuery select() {
        if(_id!=-1){
            return new SqlQuery("SELECT * FROM t_reservations WHERE c_id=?;", _id);
        }else if(_patient!=0){
            return new SqlQuery("SELECT * FROM t_reservations WHERE c_patient=?;", _patient);
        }else{
            return new SqlQuery("SELECT * FROM t_reservations;");
        }
    }

    @Override
    public List<Object> getTable(ResultSet _rs) throws Exception {
        List<Object> list=new ArrayList<>();
        while (_rs.next()) {            
            list.add(new Reservation(_rs));
        }
        return list;
    }
}
